package com.sykj.springboot.test.designMode.multitionPattern;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Emperor {

    private static int max = 5;

    private static List<Emperor> emperorList = new ArrayList<>();

    static {
        for (int i = 0; i < max; i++) {
            emperorList.add(new Emperor("皇"+(i+1)+"帝"));
        }
    }

    private String name;

    //私有化  约束不能new出新的实例
    private Emperor(String name) {
        this.name = name;
    }

    public static Emperor getInstance(){
        Random random = new Random();
        int i = random.nextInt(max);
        return (Emperor)emperorList.get(i);
    }

}
